package com.example.wifi_test;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class PermissionUtils {
    public static int REQUEST_CODE = 2021;
    /**
     * 权限检查
     * @param ct 当前Activity
     * @param permissions 需要检查的权限
     * @return boolean
     */
    public static boolean check(Context ct,String[] permissions){
        for (String permission : permissions) {
            if (ContextCompat.checkSelfPermission(ct, permission) != PackageManager.PERMISSION_GRANTED) {
                //权限申请
                System.out.println("未授权："+permission);
                request(ct,permissions);
                return false;
            }
        }
        return true;
    }

    private static void request(Context ct,String[] permissions){
        ActivityCompat.requestPermissions((Activity) ct,permissions,REQUEST_CODE);
    }
}
